public static void CompactAndRepair(string sourceAccessFile, Microsoft.Office.Interop.Access.Application app)
{
string tempFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceAccessFile),
System.IO.Path.GetRandomFileName() + System.IO.Path.GetExtension(sourceAccessFile));
app.CompactRepair(sourceAccessFile, tempFile, false);
app.Visible = false;
System.IO.FileInfo temp = new System.IO.FileInfo(tempFile);
temp.CopyTo(sourceAccessFile, true);
temp.Delete();
}
{
string tempFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceAccessFile),
System.IO.Path.GetRandomFileName() + System.IO.Path.GetExtension(sourceAccessFile));
app.CompactRepair(sourceAccessFile, tempFile, false);
app.Visible = false;
System.IO.FileInfo temp = new System.IO.FileInfo(tempFile);
temp.CopyTo(sourceAccessFile, true);
temp.Delete();
}